package algorithm.slidingWindow;

public class LC1004 {
    public int longestOnes(int[] nums, int k) {
        int l = 0, r = 0, ans = 0, n = nums.length;

        while (r < n) {
            if (nums[r] == 0)
                k--;
            while (k < 0) {
                if (nums[l++] == 0) k++;
            }
            ans = Math.max(ans, r-l+1);
            r++;
        }
        return ans;
    }

    public static void main(String[] args) {
        LC1004 lc1004 = new LC1004();
        int[] nums = {0,0,1,1,0,0,1,1,1,0,1,1,0,0,0,1,1,1,1};
        int res = lc1004.longestOnes(nums, 3);
        System.out.println(res);
    }
}
